<style>

.minicart_title {padding:19px 0 7px 0; text-align:center;width:26px;line-height:20px; position:absolute;background:url(images/mincart_bj1.gif) ; right:-27px; border:1px solid #ccc;}
.cart-container{cursor:pointer}
/*.minicart_title ul {margin:0;padding:0;list-style-type:none}
.minicart_title li { padding-top:8px; background:url(mincart_icon.gif)no-repeat center 5px}
*/</style>

<div class="minicart_<{$widgets_id}> minicart_box" <{if $setting.show_gallery}>show_gallery="true"<{/if}>>
  <div class="minicart_title"><a  class="cart-container" style=" text-decoration:none"> <span class="cart-handle"><{t app="b2c"}>我<br />的<br />购<br />物<br />车<{/t}></span> </a><!--<li class="icon2"><span><a href="<{link app=b2c ctl=site_cart act=checkout}>">去结账</a></span></li>--></div>
  <div class="MiniCarDetail minicart_cont">
  </div>
</div>
<script>
/*-------------
*minicart迷你购物车
-----------*/

window.addEvent('domready',function(){

    var cartViewUrl='<{link app=b2c ctl="site_cart" act="view"}>';
	var MiniCarWidgets={
		init:function(){
			var minicart=this.cart= document.getElement('.minicart_<{$widgets_id}>'),
				minicart_detail=this.detailbox=minicart.getElement('.MiniCarDetail'),
				handle=this.handle=minicart.getElement('.cart-handle');
			this.display().attach();
		},
		display:function(){
			<{if $setting.show_float}>
			var count=Cookie.read('S[CART_COUNT]')||0,display;
			display=!count.toInt()?'none':'';
			if(!!['form-cart','order-create',$$('.member-center')[0]].some(function(el){return $(el)}))display='none';
			this.cart.setStyle('display',display).setStyle('position','absolute').tween('top',document.body.getScroll().y+30);
			<{/if}>
			return this;
		},
		attach:function(){
			this.handle.addEvents({
				'mouseenter':function(e){
					if((e&&this.state)||(e&&!Cookie.read('S[CART_COUNT]')))return;
					if(e&&$(e.target)==this.handle&&this.cart.getElement('.CartInfoItems'))
					return this.show();

					this.request([{url:cartViewUrl, method:'post',
						onRequest:function(){
							 this.detailbox.empty().innerHTML='<div class="loading">加载中...</div>';
						}.bind(this)
					}]);
					this.show();
				}.bind(this)
			});
			this.cart.addEvent('_show',function(e){
				this.handle.fireEvent('mouseenter');
			}.bind(this));
			window.addEvent('scroll',this.display.bind(this));
		},
		show:function(e){
			this.detailbox.setStyles({'visibility':'visible'});
			this.state=true;
			document.addEvent('click',function(){
				  this.hide();
                  document.removeEvent('click',arguments.callee);
		    }.bind(this));
		},
		hide:function(){
			this.state=false;
			this.detailbox.setStyle('visibility','hidden');
		},
		removeCart:function(el){
			var cartBox=el.getParent('.minicart-single'),self=this,url=cartBox.get('urlremove');
			if(cartBox.hasClass('havechild')){
			   var chlid_id= cartBox.get('chlid_id'),group;
			   if(group=this.detailbox.getElements('.'+chlid_id)){
				  group.each(function(ell){ell.destroy();});
			   }
		    }
			cartBox.destroy();
			if(!this.detailbox.getElement('.minicart-single')){
				this.detailbox.getElement('.nodisplay').removeClass('nodisplay');
				this.detailbox.getElement('.CartInfoItems').destroy();
			}
			var _detailbox = this.detailbox;
			this.request([{url:url,data:_detailbox,onComplete:function(re){
				var json=JSON.decode(re);
				Object.each(json,function(v,key){
					if(_detailbox && _detailbox.getElement('.'+key))
					_detailbox.getElement('.'+key).set('html',v);
				});
				MessageBox.success('<{t}>删除成功<{/t}>');
			}.bind(this),onSuccess:function(){
				self.display();
				if($('mini-cart-dialog'))$('mini-cart-dialog').destroy();
			}}]);
		},
		addEvent:function(){
			var _this=this;
			this.detailbox.getElements('.delcart').addEvent('click',function(e){
				e.stop(); _this.removeCart(this);
			});
		},
		request:function(){
			var params=Array.flatten(arguments).link({
                 'remoteURL':Type.isString,
                 'options':Type.isObject
            });
			if(!params.options)return;
            params.options.data = (params.options.data?params.options.data.toQueryString():'')+'&mini_cart_list=true';
            if(!params.options.url)return false;
			params=Object.append({
                 url:params.remoteURL,
                 method:'post',
                 onSuccess:function(re){
					 this.detailbox.innerHTML=re;
					 this.display().addEvent();
                 }.bind(this)
             },params.options||{});
             return new Request(params).send();
		}
	};

	MiniCarWidgets.init();


});
</script>
